﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using WebApp.ConfigEntity;
using WebApp.Services;

namespace WebApp.Controllers
{
    /// <summary>
    /// 获取 指定的配置属性
    /// </summary>
    [Produces("application/json")]
    [Route("api/AppSetting")]
    public class AppSettingController : Controller
    {
        public readonly DbConnectionConfigurationServicecs DbConfig;

        // IOptions 注入方式
        //private readonly IOptions<DbConnectionConfiguration> AppConfiguration;
        //public AppSettingController(IOptions<DbConnectionConfiguration> appConfiguration)
        //{
        //    AppConfiguration = appConfiguration;
        //}

        /// <summary>
        /// 可以用 DbConnectionConfigurationServicecs 注入，也可以直接用上面的 IOptions 注入 
        /// </summary>
        /// <param name="dbConnection"></param>
        public AppSettingController(DbConnectionConfigurationServicecs dbConnection)
        {
            DbConfig = dbConnection;
        }

        // GET api/values/5
        [HttpGet("{id}")]
        public string Get(string id)
        {
            switch (id.ToLower())
            {
                case "redis":
                    //return AppConfiguration.Value.Redis;
                    return DbConfig.DbConnection.Redis;
                default:
                    return "get value";
            }

        }
    }
}